<template>
    <div>
        <el-form ref="ruleForm" :model="obj" :rules="rules">
            <el-row :gutter="1">
                <el-col :span="24">
                    <el-form-item label="地址 :" prop="address" :label-width="formLabelWidth3">
                        <el-input size="small" v-model="obj.address"></el-input>
                        <span style="color: red;"> Fch不支持来自btc和bch以3开头的地址转换！</span>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="1">
                <el-col :span="24">
                    <el-form-item label="目标地址类型 :" prop="targetAddress" :label-width="formLabelWidth3">
                        <el-select v-model="obj.targetAddress" placeholder="请选择" size="small" style="width: 100%">
                            <el-option
                                v-for="item in options"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="1">
                <el-col :span="24">
                    <el-form-item label=""  :label-width="formLabelWidth3">
                        <el-button type="primary" size="small" @click="AdressChange">转换</el-button>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="1">
                <el-col :span="24">
                    <el-form-item label="转换结果 :"  :label-width="formLabelWidth3">
                        <el-input size="small" v-model="newAddress"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>

<script>
    import allApi from '../../static/fchjstool/all-api';
    export default {
        name: 'Message',
        data() {
            return {
                formLabelWidth1: '60px',
                formLabelWidth2: '80px',
                formLabelWidth3: '100px',
                options: [
                    {value: 'btc', label: 'btc'},
                    {value: 'bch', label: 'bch'},
                    {value: 'fch', label: 'fch'}
                ],
                obj:{
                    address: '',
                    targetAddress: 'btc',
                },
                rules: {
                    address: [
                        {required: true, message: '请输入地址', trigger: ['blur', 'change']}
                    ],
                },
                newAddress: ''
            }
        },
        props: ['proParm'],
        methods: {
            AdressChange() {
                this.$refs['ruleForm'].validate(async (valid) => {
                    if (valid) {
                        try {
                            this.newAddress = addressConvert(this.obj.targetAddress, this.obj.address);
                        }
                        catch (e) {
                            this.newAddress = '';
                            this.$message.error(e);
                        }

                    } else {
                        return false;
                    }
                });
            }
        }
    }
</script>

<style scoped lang="less">
    /deep/ .el-form-item__label{
        padding: 0 5px 0 0;
    }
    .line {
        width: 100%;
        height: 5px;
        margin: 5px 0;
        background-color: #e4e7ed;
        z-index: 1;
    }
</style>
